package com.yang.Thread;

/**
 * @Description: TODO
 * @Author: YangTing
 * @Date: 2024-05-14 19:39
 */
public class WindowTest {
    public static void main(String[] args) {
        SaleTicket s1 = new SaleTicket();
        Thread t1 = new Thread(s1);
        Thread t2 = new Thread(s1);
        Thread t3 = new Thread(s1);
        t1.setName("窗口1");
        t2.setName("窗口2");
        t3.setName("窗口3");
        t1.start();
        t2.start();
        t3.start();
    }
}
class SaleTicket implements Runnable{
    int i = 100;
    public void run() {
        while (true){
        synchronized (new Object()){
                if(i > 0){
                    System.out.println(Thread.currentThread().getName()+"售票,卖出票："+i);
                    i--;
                }else{
                    break;
                }
            }
        }
    }
}
